package twitter.RequestHandler;

import java.io.PrintWriter;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import twitter.Database.TwitterMaintainer;
import twitter.RequestParser.BackendRequestParser;
import twitter.RequestParser.PrimaryRequestParser;
import twitter.TwitterLibrary.SocketConfig;
import twitter.TwitterLibrary.Utility;

import Twitter.RequestSender.RequestSender;

public class PrimaryRequestHandler extends BackendHttpRequestHandler{
	
	private BackendRequestParser parser;
	
	public PrimaryRequestHandler(ReentrantReadWriteLock rwl,Utility utility) {
		super(rwl,utility);
		
		
		// TODO Auto-generated constructor stub
	}
	public void setTwitterMaintainer(TwitterMaintainer twitterMaintainer)
	{
		parser=new PrimaryRequestParser(twitterMaintainer,this.utility);
	}
	@Override
	public void parseHttpRequest(String httpInput, PrintWriter httpOutput) {
		// TODO Auto-generated method stub
		String query=httpInput.substring(0, httpInput.indexOf("end"));
		logger.info("processing one request send to primary server");
		String result=parser.readQueries(query);
		
		
		httpOutput.print(result);
		httpOutput.flush();
	}

}
